package entities;

import java.sql.Date;
import java.text.DateFormat;

public class Message {
	private final String OUTPUT_FORMAT = "%12s : %s\n";
	
	private int id;
	private int senderId;
	private Location location;
	private Date timeOfOrigin;
	private Date timeOfExpiry;
	private String message;
	
	public Message(int id, int senderId, Location location, Date timeOfOrigin, Date timeOfExpiry,
			String message) {
		super();
		this.id = id;
		this.senderId = senderId;
		this.location = location;
		this.timeOfOrigin = timeOfOrigin;
		this.timeOfExpiry = timeOfExpiry;
		this.message = message;
	}
	
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
	}
	
	public int getSenderId() {
		return senderId;
	}
	
	public void setSenderId(int senderId) {
		this.senderId = senderId;
	}
	
	public Location getLocation() {
		return location;
	}

	public void setLocation(Location location) {
		this.location = location;
	}

	public Date getTimeOfOrigin() {
		return timeOfOrigin;
	}
	
	public void setTimeOfOrigin(Date timeOfOrigin) {
		this.timeOfOrigin = timeOfOrigin;
	}
	
	public Date getTimeOfExpiry() {
		return timeOfExpiry;
	}
	
	public void setTimeOfExpiry(Date timeOfExpiry) {
		this.timeOfExpiry = timeOfExpiry;
	}
	
	public String getMessage() {
		return message;
	}
	
	public void setMessage(String message) {
		this.message = message;
	}
	
	@Override
	public String toString() {
		return String.format(OUTPUT_FORMAT, "id", "" + id) +
			String.format(OUTPUT_FORMAT, "senderId", "" + senderId) +
			String.format(OUTPUT_FORMAT, "location", String.format("lat %f, long %f", location.getLatitude(), location.getLongitude())) +
			String.format(OUTPUT_FORMAT, "timeOfOrigin", DateFormat.getInstance().format(timeOfOrigin)) +
			String.format(OUTPUT_FORMAT, "timeOfExpiry", DateFormat.getInstance().format(timeOfExpiry)) +
			String.format(OUTPUT_FORMAT, "messageText", message);
	}
}
